package org.snail.jobHierarchy.controller;

import org.snail.exception.JobLevelException;
import org.snail.exception.JsonResult;
import org.snail.jobHierarchy.bean.JobDO;
import org.snail.jobHierarchy.service.impl.JobServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("jobs")
public class JobsController {
    @Autowired
    private JobServiceImpl jobServiceImpl;


    /**
     * 上传excel岗位层级单价 保存到数据库
     * @param file
     * @param request
     * @return
     */
    @RequestMapping("saveJobExcel")
    @ResponseBody
    public JsonResult saveJobPrice(@RequestParam("file") CommonsMultipartFile file, HttpServletRequest request) throws JobLevelException {
        JsonResult result = new JsonResult();
        jobServiceImpl.saveJobPrice(file,request);
        result.setMessage("上传岗位层级单价成功");
        return result;
    }

    /**
     * 岗位层级查询
     * 查询所有的岗位层级
     * @return
     */
    @RequestMapping("findAllJobPrice")
    @ResponseBody
    public JsonResult findAllJobPrice(){
        JsonResult result = new JsonResult();
        List<JobDO> jobDOs = jobServiceImpl.findAllJobPrice();
        result.setData(jobDOs);
        result.setMessage("查询岗位层级单价成功");
        return result;
    }

}